/*
- Malt Project - string.cpp
- This document is protected by the GPL protocol.
- Writer:@Index-Flandre
*/

#include "../../include/object/array.hpp"

namespace malt
{
Object *NewArray()
{
	Array *arr = new Array();
	arr->tp = &ArrayType;
	return arr;
}
bool Array::eq(Object *obj)
{
	if (this == obj)
		return true;
	if (tp != obj->tp)
		return false;
	if (size != ((Array *)obj)->size)
		return false;
	else
	{
		for (unsigned long i = 0; i < size; i++)
		{
			if (!table[i]->eq(((Array *)obj)->table[i]))
				return false;
		}
		return true;
	}
}
void Array::repl_print()
{
	printf("\e[0m{");
	if (table != Nullptr)
		for (unsigned long i = 0; i < size; i++)
		{
			if (i != 0)
				printf(" "); // 如果是第一次循环，则不print空格
			if (table[i] != Nullptr)
				table[i]->repl_print();
		}
	printf("\e[0m}\e[0m");
}
void Array::marking()
{
	if (table != Nullptr)
		for (unsigned long i = 0; i < size; i++)
			if (table[i] != Nullptr)
				table[i]->marking();
}
}